package com.code.address;

import java.net.Socket;
import java.net.SocketAddress;

/**
 * @description:
 * @className: SocketAddress
 * @package: com.code.address
 * @author: yangzhi@hsyuntai.com
 * @date: 2019/10/17 15:50
 * @copyright: 版权归 HSYUNTAI 所有
 */
public class SocketAddressTest {

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("www.qq.com", 80);
            SocketAddress qq = socket.getRemoteSocketAddress();
            System.out.println("getLocalPort:" + socket.getLocalPort());
            socket.close();


            Socket socket2 = new Socket();
            socket2.connect(qq);
            System.out.println("getLocalPort:" + socket2.getLocalPort());
            socket2.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
